# -*- coding:utf8 -*-
import datetime
from inter_game_spider.model.models import Company
from inter_game_spider.model.config import DBSession
import time

session = DBSession()


def get_company_code():
    """
    输出所有公司名称
    :return:
    """
    result = session.query(Company.code).all()
    if len(result) < 1:
        return None
    return result


def get_current_time():
    return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")


def timestap_2_datetime(timestap):
    """
    时间戳转换成时间
    :param timestap:
    :return:
    """
    if len(str(timestap)) > 10:
        # 转换成10位
        timestap = int(timestap) / 1000
    else:
        timestap = int(timestap)
    time_local = time.localtime(timestap)
    dt = time.strftime("%Y-%m-%d %H:%M:%S", time_local)
    return dt


if __name__ == '__main__':
    # print get_company_code()
    t = 1499378392
    print timestap_2_datetime(t)